package com.yonxao.demo.crud.controller;

import com.yonxao.demo.crud.core.Ret;
import com.yonxao.demo.crud.core.RetUtil;
import com.yonxao.demo.crud.entity.Student;
import com.yonxao.demo.crud.pojo.query.ListQuery;
import com.yonxao.demo.crud.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 学生 rest-controller
 *
 * @author xiaosaguo
 * @date 2021/03/15
 */
@Api(tags = "Student相关接口")
@RestController
@RequestMapping({"/student"})
@Slf4j
public class StudentController {

    @Resource
    StudentService studentService;

    @ApiOperation("根据ID查询岗位")
    @GetMapping({"/{id}"})
    public Student getById(@PathVariable Long id) {
        return studentService.getById(id);
    }

    @ApiOperation("分页获取岗位列表")
    @GetMapping("/list")
    public List<Student> list(ListQuery query) {
        return studentService.list(query);
    }

    @ApiOperation("新增岗位")
    @PostMapping
    public Ret<Student> save(@RequestBody Student student) {
        return RetUtil.success(studentService.insert(student));
    }

    @ApiOperation("修改岗位")
    @PutMapping
    public Boolean update(@RequestBody Student student) {
        return studentService.update(student);
    }

    @ApiOperation("删除岗位")
    @DeleteMapping("/{id}")
    public Boolean remove(@PathVariable Long id) {
        return studentService.remove(id);
    }
}
